<?php
class ui_reader_default extends ui {
	/**
	 * @param Array $param = array (
	 * 		id	=>
	 * 		type		=> 		
	 * 		scr_w		=>		// 屏幕分辨率width
	 * 		scr_h		=>		// 屏幕分辨率height
	 * )
	 */
	public function __construct($S, $param) {
		parent::__construct();
		
		if ($this->uid) {
			switch ($param['type']) {
				case 'circle':
					$data_save_article = new data_save_article();
					$article = $data_save_article->one_in_circle($this->uid, $param['id']);		// 返回字段中多了一个circle_id
					break;
				case 'recommend':
					$data_recommend_article = new data_recommend_article();
					$article = $data_recommend_article->one($this->uid, $param['id']);
					loadMod('index/recommend/-1');
					break;
				case 'feed':
					$data_feed = new data_feed();
					$article = $data_feed->one_article($this->uid, $param['id']);
					break;
				case 'save':
					$data_save_article = new data_save_article();
					$article = $data_save_article->one($this->uid, $param['id']);
					break;
				case 'save_on_edit':		// save on edit与save一样，区别就是打开reader的时候直接设置成edit状态
					$data_save_article = new data_save_article();
					$article = $data_save_article->one($this->uid, $param['id']);
					break;
				case 'hot':
					$data_guest = new data_guest();
					$article = $data_guest->one_article($param['id']);
					break;
				default:
					return false;
			}
			if ($article) {
				$article['title'] = htmlspecialchars($article['title']);
				if ($this->uid and $this->uid == $article['user_id']) {			// 是否允许编辑
					$article['is_editable'] = true;
				}

				$S->assign('article_type', $param['type']);					// 文章类型
				$S->assign('article', $article);
				$S->assign('code', md5($this->uid . $article['content_id'].'uReadMe'));		// 给iframe中的校验码，uid + content_id

				// recommend的时候，标记已读
				if ($param['type'] == 'recommend') {
					$data_recommend_article->mark_is_read($this->uid, $param['id']);
				}
				
				// 构造右侧的信息窗
				$data_reader_addition = new data_reader_addition();
				$addition = $data_reader_addition->addition_info($this->uid, $param['type'], $article);
				$S->assign('addition', $addition);		// 'show_type' => 'follow/join', 'follower_id' => Int, 'inviter_id' => Int, 'accepter_id' => int,  'circle' => Array, 'articles' => Array
			}
		} else {
			echo '<script type="text/javascript">location.href="/";</script>';
		}
	}
}
?>